package com.heima.article.listern;

import com.alibaba.fastjson.JSON;
import com.heima.article.service.ApArticleConfigservice;
import com.heima.common.constants.WmNewsMessageConstants;
import org.apache.avro.data.Json;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 监听上下架的类
 */
@Component
public class DownOrUpListern {


    @Autowired
    private ApArticleConfigservice apArticleConfigservice;

    @KafkaListener(topics = WmNewsMessageConstants.WM_NEWS_UP_OR_DOWN_TOPIC)
    public void getMessage(String message){
        if(StringUtils.isNotBlank(message)){
            //类型转换
            Map map = JSON.parseObject(message, Map.class);
            Long articleId = (Long) map.get("articleId");
            /**
             * enable =1 上架
             * enable =0 下架
             */
            Integer enable = (Integer) map.get("enable");
            //2.同步修改三剑客中的is_down的值
            apArticleConfigservice.downOrUpArtlicle(articleId,enable);
        }

    }
}
